<?php
//模型
class UserTitaiModel extends MY_Model {
	function __construct(){
		parent::__construct();
		$this->table = 'user_titai';
	}
	//分页列表
	function get_list($arr=array(),$page=1,$size=10){
		$where = " where 1 ";		
		if(isset($arr['type'])){
			$where .= " and t.`type`='{$arr['type']}' ";
		}
		if(isset($arr['user_id'])){
			$where .= " and t.`user_id`='{$arr['user_id']}' ";
		}
		
		$sql  = "select id, user_id, standard, info, img, config_id from ".$this->db->dbprefix.$this->table." as t {$where} LIMIT ".($page-1)*$size .",{$size}";
		$query = $this->db->query($sql);
		$res = $query->result_array();		
		
		$sql  = "select count(*) as num from ".$this->db->dbprefix.$this->table.$where;
		$query = $this->db->query($sql);
		$row = $query->row_array();		
		return array('list'=>$res,'count' =>$row['num']);		
	}
	//全部列表
	function get_lists($arr=array()){
		$where = " where 1 ";
		
		//获取体态id
		$sql  = "select id from ".$this->db->dbprefix."user_titai_config where `type`='{$arr['type']}'";
		$query = $this->db->query($sql);
		$tt_id = $query->result_array();
		if($tt_id){
			$tt_arr=array();
			foreach($tt_id as $k=>$v){
				$tt_arr[]=$v['id'];
			}			
			$tt_id = implode(',',$tt_arr);
			$where .= " and config_id in ({$tt_id}) ";
		}
			
	
		if(isset($arr['user_id'])){
			$where .= " and `user_id`='{$arr['user_id']}' ";
		}
		
		$sql  = "select id, user_id, standard, info, img, config_id from ".$this->db->dbprefix.$this->table.$where;
		
		$query = $this->db->query($sql);
		$res = $query->result_array();
		return $res;		
	}
	//详情
	function get_info($id){
		$sql  = "select * from ".$this->db->dbprefix.$this->table." where id='{$id}'  ";
		$query = $this->db->query($sql);
		$row = $query->row_array();		
		return $row;
	}
	//唯一条件获取详情
	function unique_get_info($field,$value){
		$sql  = "select * from ".$this->db->dbprefix.$this->table." where {$field}='{$value}' ";
		$query = $this->db->query($sql);
		$row = $query->row_array();		
		return $row;
	}
	
}

